package com.example.black.myapplication.filtercolorrgb;

import android.content.Context;
import android.graphics.BlurMaskFilter;
import android.graphics.Canvas;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;

import com.example.black.myapplication.R;

/**
 * 留下一个课题，如何创建彩色的阴影
 */
public class FilerButton extends android.support.v7.widget.AppCompatButton {

    private RectF rectF;
    private BlurMaskFilter blurMaskFilter;

    public FilerButton(Context context) {
        super(context);
        initConfig();
    }

    public FilerButton(Context context, AttributeSet attrs) {
        super(context, attrs);
        initConfig();
    }

    public FilerButton(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initConfig();
    }
    private void initConfig() {
        rectF = new RectF(100, 100, 300, 200);
        setLayerType(View.LAYER_TYPE_SOFTWARE,getPaint());
    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
        blurMaskFilter = new BlurMaskFilter(165, BlurMaskFilter.Blur.OUTER);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        getPaint().setColor(getResources().getColor(R.color.colorPrimaryBlueDark));
        getPaint().setMaskFilter(blurMaskFilter);
        canvas.drawRect(rectF,getPaint());
    }
}
